﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Tile
{
    class Bola
    {
        Texture2D texture;
        Vector2 position;
        Rectangle sizeBola;
        SoundEffect som;
        int velocityX = 5;
        int velocityY = -5;

        public Bola(GameWindow janela, Texture2D textura, Vector2 position, SoundEffect sound)
        {
            this.texture = textura;
            this.sizeBola = textura.Bounds;
            this.position = new Vector2((janela.ClientBounds.Width / 2 - this.sizeBola.Width / 2),360); 
            this.som = sound;
        }

        public void Update(GameWindow janela, GameTime gameTime, Palleta player1) 
        {
            this.sizeBola.X = (int)position.X;
            this.sizeBola.Y = (int)position.Y;     

            if (position.Y < 0 || position.Y > janela.ClientBounds.Height - texture.Height || position.Y < 5)
            {
                velocityY *= -1;
                som.Play(); 
            }

            if (position.X > janela.ClientBounds.Width - texture.Width || position.X < 0)
            {
                velocityX *= -1;
                som.Play();
            }

            if (player1.GetSize.Intersects(this.sizeBola))
            {
                velocityY *= -1;
            }




            position.X += velocityX;
            position.Y += velocityY;   
        }



        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);  
        }



    }
}
